package com.itheima.service.impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.pojo.EmpJobData;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentCountData;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    /**
     * 员工职位统计
     *
     * @return
     */
    /*@Override
    public JobOption getEmpJobData() {
        ArrayList<String> posList = new ArrayList<>();
        ArrayList<Integer> totalList = new ArrayList<>();

        List<EmpJobData> empJobDataList = reportMapper.getEmpJobData();
        for (EmpJobData empJobData : empJobDataList) {
            String pos = empJobData.getPos();
            posList.add(pos);
            Integer total = empJobData.getTotal();
            totalList.add(total);
        }

        return new JobOption(posList, totalList);
    }*/
    @Override
    public JobOption getEmpJobData() {
        List<Map<String, Object>> jobDataList = reportMapper.empJobDataMap();
        List<String> jobList = jobDataList.stream()// 流中元素是map
                .map(map -> map.get("pos").toString())// 职位的字符串
                .collect(Collectors.toList());

        List<Integer> dataList = jobDataList.stream()
                .map(map -> Integer.parseInt(map.get("total").toString()))
                .collect(Collectors.toList());

        return new JobOption(jobList, dataList);
    }

    /*@Override
    public Map<String, List> getEmpJobData() {
        ArrayList<String> jobList = new ArrayList<>();
        ArrayList<Long> dataList = new ArrayList<>();
        List<Map> mapList = reportMapper.getEmpJobData();
        for (Map map : mapList) {
            String job = (String) map.get("pos");
            jobList.add(job);
            Long total = (Long) map.get("total");
            dataList.add(total);
        }

        HashMap<String, List> map = new HashMap<>();
        map.put("jobList", jobList);
        map.put("dataList", dataList);
        return map;
    }*/


    /**
     * 员工性别统计
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        List<Map<String, Object>> dataList = reportMapper.getEmpGenderData();
        return dataList;
    }


    /**
     * 班级人数统计
     *
     * @return
     */
    @Override
    public StudentOption getStudentCountData() {
        ArrayList<String> clazzList = new ArrayList<>();
        ArrayList<Integer> dataList = new ArrayList<>();
        List<StudentCountData> studentCountDataList = reportMapper.getStudentCountData();
        for (StudentCountData studentCountData : studentCountDataList) {
            String clazzName = studentCountData.getClazzName();
            clazzList.add(clazzName);
            Integer total = studentCountData.getTotal();
            dataList.add(total);
        }

        return new StudentOption(clazzList, dataList);
    }


    /**
     * 学员学历统计
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return reportMapper.getStudentDegreeData();
    }


}
